package org.geektime.config;

import org.geektime.beanfactory.CatBeanFactory;
import org.geektime.entity.Cat;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfig {

  private CatBeanFactory catBeanFactory;

  @Bean
  public Cat tomCat() {
    Cat tomCat = new Cat();
    tomCat.setColor("yellow");
    tomCat.setName("xal");
    tomCat.setPersonName("xuanlong");
    return tomCat;
  }

  @Bean
  public CatBeanFactory createRunnableFactoryBean() {
    catBeanFactory = new CatBeanFactory();
    return catBeanFactory;
  }

  @Bean
  public Cat factoryCat() {
    try {
      return catBeanFactory.getObject();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
}
